import React from "react";
import { Button, Modal, Form, Input,Card } from 'antd';
import { login, usernameExist } from "../services/user";
import {useNavigate} from 'react-router-dom';
export default function Reg() {
    let navigate = useNavigate();
    const onFinish = async (values) => {
        let data = await login(values);
        if(data.status == 1){
          localStorage.setItem("token",data.token);
          navigate("/manage");
        }else{
          Modal.error({
            title: '错误',
            content: '验证失败',
          });
        }
    };

    const onFinishFailed = (errorInfo) => {
        console.log("Failed:", errorInfo);
    };
    // 栅格
    return (
      <Card title="登录" style={{ width: 500,margin:"auto" }}>
        <Form
            name="basic"
            labelCol={{
                span: 8,
            }}
            wrapperCol={{
                span: 16,
            }}
            initialValues={{
                remember: true,
            }}
            onFinish={onFinish}
            onFinishFailed={onFinishFailed}
            autoComplete="off"
        >
            <Form.Item
                label="用户名"
                name="username"
                hasFeedback
                rules={[
                    {
                        required: true,
                        message: "用户名不能为空",
                    }
                  
                ]}
            >
                <Input />
            </Form.Item>

            <Form.Item
                label="密码"
                name="pwd"
                rules={[
                    {
                        required: true,
                        message: "密码不能为空",
                    },
                ]}
            >
                <Input.Password />
            </Form.Item>
           
           

            <Form.Item
                wrapperCol={{
                    offset: 8,
                    span: 16,
                }}
            >
                <Button type="primary" htmlType="submit">
                    Submit
                </Button>
            </Form.Item>
        </Form>
        </Card>
    );
}
